package com.haiheng.voiceandbook

import android.os.Environment
import android.util.Log
import com.haiheng.voiceandbook.utils.AppUtils
import com.haiheng.voiceandbook.utils.SpUtil
import com.lztek.toolkit.AddrInfo
import com.lztek.toolkit.Lztek
import com.tencent.smtt.utils.LogFileUtils
import com.xmlywind.sdk.common.models.sigdsp.pb.App
import java.io.File

class Constants {
    companion object {
        //app私有目录
//        val ROOT_PATH =
//            MyApplication.getInstance().applicationContext.getFilesDir().getAbsolutePath()

        //外部内存卡存储
        val ROOT_PATH =Environment.getExternalStorageDirectory().absolutePath

        const val BOOK = "BOOK"
        const val DEVICEID = "deviceid" //device

//        const val SETTING_PASSWORD = "654321"
        const val SETTING_PASSWORD = "sea456"
        //apk存储文件夹
        const val APK = "apk"
        const val APK_NAME = "VoiceAcdBook.apk"

        val BOOK_PATH = "${ROOT_PATH}/${BOOK}"
        val APK_PATH = "${ROOT_PATH}/${APK}"

        const val SUFFIX_TXT = ".txt"
        const val SUFFIX_PDF = ".pdf"
        const val SUFFIX_EPUB = ".epub"
        const val SUFFIX_ZIP = ".zip"
        const val SUFFIX_CHM = ".chm"
        const val TAIZHOU_WEBVIEW_URL = "https://yjy.elvyoo.com/h5/tz/pages/main/index"


        //图书馆编码
        const val haiheng_code : String = "CN-518000-HHLIB"
        //燕京理工
        const val yanjing_code : String = "CN-065201-YJLGLIB"
        const val taizhou_code : String = "CN-318000-TZLIB"
        const val pinghu_library_name :String = "海恒图书馆"
//        const val haiheng_appid:String = "LDhlB3RJstJba2HX";//小海鸥测试环境测试
//        const val haiheng_appid:String = "6OCcXpP6I6KJuhGE";//正式
        const val haiheng_appid:String = "qqir2raXgHEGdnRs";//小海鸥正式环境测试
//        const val haiheng_appid:String = "W4QvN4VCf3zgxkgT";//台州

//        const val haiheng_code : String = "CN-314200-PLLIB"
//        const val pinghu_library_name :String = "平湖市图书馆"

//        const val haiheng_code : String = "CN-318000-TZLIB"
//        const val pinghu_library_name :String = "台州市图书馆"

//        const val haiheng_code : String = "CN-323300-SCLIB"
//        const val pinghu_library_name :String = "遂昌县图书馆"

//        const val BASE_URL = "https://test.seaeverit.com/"
        const val BASE_URL = "https://yidu.seaeverit.com/"

        /**
         * 专辑
         */
        const val AlbumPage_URL = "https://yidu.seaeverit.com/webview/index.html#/pages/albumPage/albumPage"

        const val PRE_BOOK = "MyBook"
        const val SCREEN_SAVER_FILE_NAME = "ScreenPic"
        val PRE_PACKAGE_BOOK_PATH = "${ROOT_PATH}/${PRE_BOOK}"

        const val SP_APPID = "sp_appid"
        const val SP_LIBRARY_CODE = "sp_livrary_code"
        const val SP_LIBRARY_NAME = "sp_library_name"
        const val SP_LIBRARY_LOGO = "sp_library_logo"
        const val SP_MAON_ORDER_CONFIG = "sp_main_order_config"//首页配置，默认1234对应热门专辑，最新专辑，最新图书，热门图书
        const val SP_TAIZHOU_H5_URL  = "sp_taizhou_h5_url"//台州游省心连接
        const val SP_SWITCH_EXIT_OPEN_APP  = "switchExitOpenApp"//退出app重新拉起
        const val SP_IS_APP_IN_FOREGROUND  = "isAppInForeground"//app是否在前台
        const val SP_IS_OPEN_YOU_SHENG_XIN  = "isOpenYouShengXin"//是否打开游省心
        const val SP_DOWNLOAD_INFO  = "download_info"//apk下载记录
        const val SP_IS_OPEN_SCREEN_SAVER = "SP_IS_OPEN_SCREEN_SAVER"
        const val SP_SCREEN_SAVER_TIME = "SP_SCREEN_SAVER_TIME"
        const val SP_SCREEN_SAVER_PIC_TIME = "SP_SCREEN_SAVER_PIC_TIME"
        //由于后台接口支持有限，所以只能通过固定的版本号和版本民获取版本配置文件
        const val VERSION_VER_NO = "211223000"
        const val VERSION_VER_NAME = "hh_voice_and_book_version_config"

        fun getDevicesId():String{
            var ethMac = ""
            try {

                ethMac = AppUtils.getUniqueId(MyApplication.getInstance().applicationContext)
                if (ethMac.isBlank()){
                    ethMac = AppUtils.getMacAddress()
                }
                if (ethMac.isBlank()){
                    var le = Lztek.create(MyApplication.getInstance().applicationContext)
                    ethMac = le.ethMac
                }

            }catch (ex:Exception){
                if (ethMac.isBlank()){
                    ethMac = AppUtils.getMacAddress()
                }
            }
            Log.i("dddd ","ethmac:${ethMac}")
            return ethMac
        }
        fun getLibraryCode():String{
            var code = SpUtil.getString(MyApplication.getInstance().applicationContext,
                SP_LIBRARY_CODE, haiheng_code)
            return code;
        }

        fun getAppId() : String{
            var appId = SpUtil.getString(MyApplication.getInstance().applicationContext,
                SP_APPID,haiheng_appid)
            return appId
        }

        fun getLibraryName() : String{
            var name = SpUtil.getString(MyApplication.getInstance().applicationContext,
                SP_LIBRARY_NAME,pinghu_library_name)
            return name
        }

        fun getLibraryLogo() : String{
            var name = SpUtil.getString(MyApplication.getInstance().applicationContext,
                SP_LIBRARY_LOGO,"")
            return name
        }

        fun getTaiZhouH5Url() : String{
            var url = SpUtil.getString(MyApplication.getInstance().applicationContext,
                SP_TAIZHOU_H5_URL,TAIZHOU_WEBVIEW_URL)
            return url
        }

        fun getMainOrderConfig() : String{
            var config = SpUtil.getString(MyApplication.getInstance().applicationContext,
                SP_MAON_ORDER_CONFIG,"1234")
            return config
        }
        fun isExitOpenApp():Boolean{
            var isExitOpenApp =  SpUtil.getBoolean(MyApplication.getInstance().applicationContext,
                SP_SWITCH_EXIT_OPEN_APP,true)
            return  isExitOpenApp
        }
        fun isAppInForeground():Boolean{
            var isExitOpenApp =  SpUtil.getBoolean(MyApplication.getInstance().applicationContext,
                SP_IS_APP_IN_FOREGROUND,true)
            return isExitOpenApp
        }

        fun isOpenYouShengXin():Boolean{//游省心开关
            var isOpenYouShengXin =  SpUtil.getBoolean(MyApplication.getInstance().applicationContext,
                SP_IS_OPEN_YOU_SHENG_XIN,false)
            return isOpenYouShengXin
        }

        fun isOpenSreenSaver():Boolean{
            return SpUtil.getBoolean(MyApplication.getInstance().applicationContext,
                SP_IS_OPEN_SCREEN_SAVER,false)
        }
        fun getSreenSaverTime():Int{
            return SpUtil.getInt(MyApplication.getInstance().applicationContext,
                SP_SCREEN_SAVER_TIME,600)
        }
        fun getSreenSaverPicTime():Int{
            return SpUtil.getInt(MyApplication.getInstance().applicationContext,
                SP_SCREEN_SAVER_PIC_TIME,10)
        }

        fun isPicFileExists():Boolean{
            val screenPicFolder = File(Environment.getExternalStorageDirectory(),
                SCREEN_SAVER_FILE_NAME
            )
            if (screenPicFolder.exists() && screenPicFolder.isDirectory) {
                val files = screenPicFolder.listFiles()
                if (files != null && files.isNotEmpty()) {
                    return true
                }
            }
            return false
        }
    }

    interface EBOOK_CATEGORIES {
        companion object {
            const val HOME = "首页分类"
            const val FIND = "更多选项分类"
        }
    }
}

